package com.ruoyi.financial.letter;

import com.rabbitmq.client.Channel;
import com.ruoyi.financial.domain.TCwPaymentPlan;
import com.ruoyi.financial.service.ITCwPaymentPlanService;
import com.ruoyi.financial.util.SendMsgUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DeadConsumer {

    @Autowired
    private ITCwPaymentPlanService tCwPaymentPlanService;

    @RabbitListener(queues = "financialdeadLetterQueue")
    public void receiveBizMsg1(Message message, Channel channel) throws IOException {
        System.out.println("收到<<<死信>>>消息1：" + new String(message.getBody()));
        String s = new String(message.getBody());

        TCwPaymentPlan plan = tCwPaymentPlanService.selectTCwPaymentPlanById(Long.parseLong(s));
        if (plan.getPayState()==2){
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
            System.out.println("已付款=============");
        }else {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
            System.out.println("死信队列已消费=============");
          //  SendMsgUtil.send("17630978027",200);
        }
    }



}